import { View } from "../../../mvc/core/View";
import { ILayOut } from "../../../../modules/interfaces/ILayOut";
import { Cache } from "../../cache/Cache";
import { CareerUtil } from "../common/util/CareerUtil";
import { NewBattleFieldBufferConfig } from "../../resource/NewBattleFieldBufferConfig";
import { TimelineLite } from "../../../../com/greensock/TimelineLite";
import { TweenLite } from "../../../../com/greensock/TweenLite";
import { Global } from "../../../../com/gengine/global/Global";
import { SNewBattleFieldInspireInfo } from "../../../../Message/Public/SNewBattleFieldInspireInfo";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Language } from "../../../../extend/language/Language";
import { NewBattlefieldSparkMaxCell } from "./cell/NewBattlefieldSparkMaxCell";
import { MoneyItem } from "../common/item/MoneyItem";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { LayerManager } from "../../manager/LayerManager";
import { NewBattlefieldSparkMiniCell } from "./cell/NewBattlefieldSparkMiniCell";
import { MsgManager } from "../../manager/MsgManager";
import { EActiveType } from "../../../../Message/Public/EActiveType";
import { PulseSharedObject } from "../player/PulseSharedObject";
import { Alert } from "../../../../com/mui/controls/Alert";
import { CheckBoxWin } from "../common/alertwins/CheckBoxWin";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class NewBattlefieldSparkView
    
    export  class NewBattlefieldSparkView extends View implements ILayOut
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */getAttackAttribute(): Array<any>
        {
            var loc1=Cache.instance.role.entityInfo.careerEnable;
            var loc2=0;
            if (loc1 == 0 || CareerUtil.isPhysicalCareer(loc1)) 
            {
                if (Cache.instance.role.fightAttribute) 
                {
                    loc2 = Cache.instance.role.fightAttribute.physicalAttack;
                }
            }
            else if (Cache.instance.role.fightAttribute) 
            {
                loc2 = Cache.instance.role.fightAttribute.magicAttack;
            }
            var loc3=NewBattleFieldBufferConfig.instance.getAllAttackNumber(this.allInfo ? this.allInfo.attackLevel : 0);
            var loc4=NewBattleFieldBufferConfig.instance.getPersonalAttackPer(this.personalInfo ? this.personalInfo.attackLevel : 0);
            return [loc2, loc4, loc3];
        }

        /* internal  */getLifeAttribute(): Array<any>
        {
            var loc1=0;
            if (Cache.instance.role.fightAttribute) 
            {
                loc1 = Cache.instance.role.fightAttribute.maxLife;
            }
            var loc2=NewBattleFieldBufferConfig.instance.getAllLifeNumber(this.allInfo ? this.allInfo.lifeLevel : 0);
            var loc3=NewBattleFieldBufferConfig.instance.getPersonalLifePer(this.personalInfo ? this.personalInfo.lifeLevel : 0);
            return [loc1, loc3, loc2];
        }

        public shakeObj(arg1: Object /* flash.display.DisplayObject */): void
        {
            var obj: Object /* flash.display.DisplayObject */;
            var oldX: number;
            var oldY: number;
            var timeLite: TimelineLite;

            var loc1;
            oldY = NaN;
            timeLite = null;
            obj = arg1;
            if (this._isTweening) 
            {
                return;
            }
            this._isTweening = true;
            oldX = obj.x;
            oldY = obj.y;
            timeLite = new TimelineLite();
            timeLite.append(new TweenLite(obj, 0.05, {"y": oldY - 15}));
            timeLite.append(new TweenLite(obj, 0.05, {"y": oldY + 15}));
            timeLite.append(new TweenLite(obj, 0.04, {"y": oldY - 10}));
            timeLite.append(new TweenLite(obj, 0.03, {"y": oldY + 5}));
            timeLite.append(new TweenLite(obj, 0.03, {"y": oldY - 5, "onComplete":(): void
            {
                obj.y = oldY;
                _isTweening = false;
                timeLite.stop();
                timeLite = null;
                return;
            }}))
            timeLite.play();
            return;
        }

        public resetPosition(): void
        {
            this._minView.x = Global.stage.stageWidth - 62;
            this._minView.y = 193;
            this._maxView.x = (Global.stage.stageWidth - 580) / 2;
            this._maxView.y = (Global.stage.stageHeight - 350) / 2;
            return;
        }

        public updateTotalInspire(arg1: SNewBattleFieldInspireInfo): void
        {
            if (this.allInfo && arg1.attackLevel > this.allInfo.attackLevel || !this.allInfo && arg1.attackLevel > 0) 
            {
                this.shakeObj(this._sparkMiniCell4);
                this.shakeObj(this._sparkMaxCell4);
            }
            if (this.allInfo && arg1.lifeLevel > this.allInfo.lifeLevel || !this.allInfo && arg1.lifeLevel > 0) 
            {
                this.shakeObj(this._sparkMiniCell5);
                this.shakeObj(this._sparkMaxCell5);
            }
            this.allInfo = arg1;
            this._sparkMiniCell4.updateLevel(arg1.attackLevel);
            this._sparkMiniCell5.updateLevel(arg1.lifeLevel);
            this._sparkMaxCell4.updateLevel(arg1.attackLevel, NewBattleFieldBufferConfig.instance.getAllAttackNumber(arg1.attackLevel).toString());
            this._sparkMaxCell5.updateLevel(arg1.lifeLevel, NewBattleFieldBufferConfig.instance.getAllLifeNumber(arg1.lifeLevel).toString());
            this.updateTipTxt();
            return;
        }

        /* internal  */createMinView(): void
        {
            this._minView = new Object /* flash.display.Sprite */();
            this.addChild(this._minView);
            ObjCreate.createBg(0, 0, 62, 300, this._minView, "WindowCenterA");
            this._btnShow = GlobalClass.getInstance("showBtn");
            ObjCreate.setObjAttri(this._btnShow, 33, 17, 24, 22, this._minView);
            this._btnShow.scaleX = -1;
            this._sparkMiniCell1 = this.createMiniCell(5, 28, ImagesConst.sparkMiniCellText1);
            this._sparkMiniCell2 = this.createMiniCell(5, 77, ImagesConst.sparkMiniCellText2);
            this._sparkMiniCell3 = this.createMiniCell(5, 126, ImagesConst.sparkMiniCellText3);
            this._sparkMiniCell4 = this.createMiniCell(5, 173, ImagesConst.sparkMiniCellText4);
            this._sparkMiniCell5 = this.createMiniCell(5, 221, ImagesConst.sparkMiniCellText5);
            this._btnWorshipMini = ObjCreate.createGButton(Language.getString(41674), 8, 270, 50, 22, this._minView, "ButtonRedMini");
            this._minView.addEventListener(flash.events.MouseEvent.CLICK, this.onClickShowMax);
            this._btnWorshipMini.addEventListener(flash.events.MouseEvent.CLICK, this.onWorship);
            return;
        }

        /* internal  */createMaxView(): void
        {
            this._maxView = new Object /* flash.display.Sprite */();
            this._maxView.x = (Global.stage.stageWidth - 580) / 2;
            this._maxView.y = (Global.stage.stageHeight - 350) / 2;
            this._maxView.visible = false;
            this.addChild(this._maxView);
            this._maxBg = new Object /* flash.display.Bitmap */();
            this._maxView.addChild(this._maxBg);
            this._bmpSelfState = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bmpSelfState, 125, 80, -1, -1, this._maxView);
            this._bmpForceState = new Object /* flash.display.Bitmap */();
            ObjCreate.setObjAttri(this._bmpForceState, 408, 80, -1, -1, this._maxView);
            this._btnMinView = GlobalClass.getInstance("showBtn");
            ObjCreate.setObjAttri(this._btnMinView, 492, 59, 24, 22, this._maxView);
            this._sparkMaxCell1 = new NewBattlefieldSparkMaxCell(ImagesConst.sparkMaxCellText1, Language.getString(41675), true);
            this._sparkMaxCell2 = new NewBattlefieldSparkMaxCell(ImagesConst.sparkMaxCellText2, Language.getString(41676), true);
            this._sparkMaxCell3 = new NewBattlefieldSparkMaxCell(ImagesConst.sparkMaxCellText3, Language.getString(41677), false);
            this._sparkMaxCell4 = new NewBattlefieldSparkMaxCell(ImagesConst.sparkMaxCellText4, Language.getString(41678), false);
            this._sparkMaxCell5 = new NewBattlefieldSparkMaxCell(ImagesConst.sparkMaxCellText5, Language.getString(41679), false);
            ObjCreate.setObjAttri(this._sparkMaxCell1, 38, 110, -1, -1, this._maxView);
            ObjCreate.setObjAttri(this._sparkMaxCell2, 141, 110, -1, -1, this._maxView);
            ObjCreate.setObjAttri(this._sparkMaxCell3, 244, 110, -1, -1, this._maxView);
            ObjCreate.setObjAttri(this._sparkMaxCell4, 373, 110, -1, -1, this._maxView);
            ObjCreate.setObjAttri(this._sparkMaxCell5, 476, 110, -1, -1, this._maxView);
            ObjCreate.createBg(357, 80, 1, 150, this._maxView, "VSpliteLine");
            this._tfAttack = ObjCreate.createTextField("", 103, 215, 450, 20, this._maxView);
            this._tfLife = ObjCreate.createTextField("", 103, 235, 450, 20, this._maxView);
            ObjCreate.createBg(78, 269, 470, 2, this._maxView, "SplitLine");
            this._tfWorship = ObjCreate.createTextField(Language.getString(41680), 340, 284, 70, 20, this._maxView);
            this._moneyItem = new MoneyItem();
            this._moneyItem.update(0, EPrictUnit._EPriceUnitGold);
            ObjCreate.setObjAttri(this._moneyItem, 350, 284, -1, -1, this._maxView);
            this._tfCanNotWorship = ObjCreate.createTextField(Language.getString(41692), 370, 284, 120, 20, this._maxView, GlobalStyle.textFormat6);
            this._tfCanNotWorship.visible = false;
            this._btnWorship = ObjCreate.createGButton(Language.getString(41674), 456, 281, 50, 22, this._maxView, "ButtonRedMini");
            this._btnWorship.addEventListener(flash.events.MouseEvent.CLICK, this.onWorship);
            ObjCreate.createBitmap(ImagesConst.Fire, 84, 300, this._maxView);
            this._tfTips = ObjCreate.createTextField("", 111, 308, 450, 20, this._maxView, GlobalStyle.textFormatGreen);
            this._tfTips.htmlText = Language.getString(41681);
            LoaderHelp.addResCallBack(ResFileConst.newBFSparkMax, this.onResCompl);
            this._btnMinView.addEventListener(flash.events.MouseEvent.CLICK, this.onClickMinView);
            if (Cache.instance.newBattlefield.allInfo) 
            {
                this.updateTotalInspire(Cache.instance.newBattlefield.allInfo);
            }
            if (Cache.instance.newBattlefield.personalInfo) 
            {
                this.updatePersonalInspire(Cache.instance.newBattlefield.personalInfo);
            }
            return;
        }

        /* internal  */onClickMinView(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.minSparkView();
            return;
        }

        /* internal  */onResCompl(): void
        {
            this._maxBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.sparkMaxBg);
            this._bmpSelfState.bitmapData = GlobalClass.getBitmapData(ImagesConst.sparkSelfAddState);
            this._bmpForceState.bitmapData = GlobalClass.getBitmapData(ImagesConst.sparkForceAddState);
            return;
        }

        /* internal  */init(): void
        {
            this.layer = LayerManager.uiLayer;
            this.createChildren();
            var loc1=new SNewBattleFieldInspireInfo();
            loc1.attackLevel = 5;
            loc1.lifeLevel = 5;
            return;
        }

        /* internal  */createChildren(): void
        {
            this.createMinView();
            this.createMaxView();
            this.resetPosition();
            return;
        }

        public maxSparkView(): void
        {
            this._maxView.visible = true;
            this._minView.visible = false;
            return;
        }

        /* internal  */onClickShowMax(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target != this._btnWorshipMini) 
            {
                this.maxSparkView();
            }
            return;
        }

        /* internal  */createMiniCell(arg1: int, arg2: int, arg3: string): NewBattlefieldSparkMiniCell
        {
            var loc1;
            (loc1 = new NewBattlefieldSparkMiniCell(arg3)).x = arg1;
            loc1.y = arg2;
            this._minView.addChild(loc1);
            return loc1;
        }

        public minSparkView(): void
        {
            this._maxView.visible = false;
            this._minView.visible = true;
            return;
        }

        /* internal  */onWorship(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=0;
            var loc4=0;
            if (this.personalInfo) 
            {
                loc1 = this.personalInfo.attackLevel + this.personalInfo.lifeLevel;
                if (loc1 >= this._maxLevel) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(41693));
                    this._btnWorshipMini.enabled = false;
                    this._tfCanNotWorship.visible = true;
                    this._tfWorship.visible = false;
                    this._moneyItem.visible = false;
                    this._btnWorship.enabled = false;
                }
            }
            else 
            {
                loc1 = 0;
            }
            if (Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeBattleFieldFeteLowerPrice)) 
            {
                loc2 = NewBattleFieldBufferConfig.instance.getLowerCost(loc1);
            }
            else 
            {
                loc2 = NewBattleFieldBufferConfig.instance.getCost(loc1);
            }
            var loc3;
            if (loc3 = !PulseSharedObject.isTodayNotTips("newBattlefieldSparkAlert")) 
            {
                Alert.alertWinRenderer = CheckBoxWin;
                Alert.show(Language.getStringByParam(41682, loc2.toString()), null, Alert.OK | Alert.CANCEL, null, this.onWorshipClose);
            }
            else 
            {
                loc4 = 0;
                if (this.personalInfo) 
                {
                    loc4 = this.personalInfo.attackLevel + this.personalInfo.lifeLevel;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.NewBattlefieldWorship, loc4));
            }
            return;
        }

        /* internal  */onWorshipClose(arg1: int, arg2: Boolean): void
        {
            var loc1=0;
            if (this.personalInfo) 
            {
                loc1 = this.personalInfo.attackLevel + this.personalInfo.lifeLevel;
            }
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.NewBattlefieldWorship, loc1));
            }
            if (arg2) 
            {
                PulseSharedObject.save("newBattlefieldSparkAlert", true);
            }
            return;
        }

        public updatePersonalInspire(arg1: SNewBattleFieldInspireInfo): void
        {
            var loc2=0;
            if (this.personalInfo && arg1.attackLevel > this.personalInfo.attackLevel || !this.personalInfo && arg1.attackLevel > 0) 
            {
                this.shakeObj(this._sparkMiniCell1);
                this.shakeObj(this._sparkMaxCell1);
            }
            if (this.personalInfo && arg1.lifeLevel > this.personalInfo.lifeLevel || !this.personalInfo && arg1.lifeLevel > 0) 
            {
                this.shakeObj(this._sparkMiniCell2);
                this.shakeObj(this._sparkMaxCell2);
            }
            if (this.personalInfo && arg1.attackLevel + arg1.lifeLevel > this.personalInfo.attackLevel + this.personalInfo.lifeLevel || !this.personalInfo && arg1.attackLevel + arg1.lifeLevel > 0) 
            {
                this.shakeObj(this._sparkMiniCell3);
                this.shakeObj(this._sparkMaxCell3);
            }
            this.personalInfo = arg1;
            this._sparkMiniCell1.updateLevel(arg1.attackLevel);
            this._sparkMiniCell2.updateLevel(arg1.lifeLevel);
            this._sparkMiniCell3.updateLevel(arg1.attackLevel + arg1.lifeLevel);
            this._sparkMaxCell1.updateLevel(arg1.attackLevel, NewBattleFieldBufferConfig.instance.getPersonalAttackPer(arg1.attackLevel) + "%");
            this._sparkMaxCell2.updateLevel(arg1.lifeLevel, NewBattleFieldBufferConfig.instance.getPersonalLifePer(arg1.lifeLevel) + "%");
            this._sparkMaxCell3.updateLevel(arg1.attackLevel + arg1.lifeLevel, NewBattleFieldBufferConfig.instance.getHonorPer(arg1.attackLevel + arg1.lifeLevel) + "%");
            var loc1=arg1.attackLevel + arg1.lifeLevel;
            if (loc1 < this._maxLevel) 
            {
                this._btnWorshipMini.enabled = true;
                this._btnWorship.enabled = true;
                this._tfCanNotWorship.visible = false;
                this._moneyItem.visible = true;
                this._tfWorship.visible = true;
                if (Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeBattleFieldFeteLowerPrice)) 
                {
                    loc2 = NewBattleFieldBufferConfig.instance.getLowerCost(loc1);
                }
                else 
                {
                    loc2 = NewBattleFieldBufferConfig.instance.getCost(loc1);
                }
                this._moneyItem.update(loc2, EPrictUnit._EPriceUnitGold);
            }
            else 
            {
                this._btnWorshipMini.enabled = false;
                this._btnWorship.enabled = false;
                this._tfCanNotWorship.visible = true;
                this._moneyItem.visible = false;
                this._tfWorship.visible = false;
            }
            this.updateTipTxt();
            return;
        }

        public updateTipTxt(): void
        {
            var loc1=this.getAttackAttribute();
            var loc2=this.getLifeAttribute();
            this._tfAttack.htmlText = "当前攻击: " + "<font color = \'#f0ea3f\'>战神附体+" + loc1[1] + "%</font>" + " + " + "<font color = \'#f0ea3f\'>全民皆兵+" + loc1[2] + "</font>" + " = " + loc1[0];
            this._tfLife.htmlText = "当前生命: " + "<font color = \'#f0ea3f\'>血神附体+" + loc2[1] + "%</font>" + " + " + "<font color = \'#f0ea3f\'>全民最强+" + loc2[2] + "</font>" + " = " + loc2[0];
            return;
        }

        /* internal */ /* var */_minView: Object /* flash.display.Sprite */;

        /* internal */ /* var */_btnShow: Object /* flash.display.SimpleButton */;

        /* internal */ /* var */_sparkMiniCell1: NewBattlefieldSparkMiniCell;

        /* internal */ /* var */_sparkMiniCell2: NewBattlefieldSparkMiniCell;

        /* internal */ /* var */_sparkMiniCell3: NewBattlefieldSparkMiniCell;

        /* internal */ /* var */_sparkMiniCell5: NewBattlefieldSparkMiniCell;

        /* internal */ /* var */_btnWorshipMini: GButton;

        /* internal */ /* var */_maxLevel: int=10;

        /* internal */ /* var */_sparkMiniCell4: NewBattlefieldSparkMiniCell;

        /* internal */ /* var */_maxView: Object /* flash.display.Sprite */;

        /* internal */ /* var */_maxBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnMinView: Object /* flash.display.SimpleButton */;

        /* internal */ /* var */_bmpSelfState: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpForceState: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sparkMaxCell1: NewBattlefieldSparkMaxCell;

        /* internal */ /* var */_sparkMaxCell2: NewBattlefieldSparkMaxCell;

        /* internal */ /* var */_sparkMaxCell3: NewBattlefieldSparkMaxCell;

        /* internal */ /* var */_sparkMaxCell4: NewBattlefieldSparkMaxCell;

        /* internal */ /* var */_tfTips: Object /* flash.text.TextField */;

        /* internal */ /* var */personalInfo: SNewBattleFieldInspireInfo;

        /* internal */ /* var */allInfo: SNewBattleFieldInspireInfo;

        /* internal */ /* var */_tfAttack: Object /* flash.text.TextField */;

        /* internal */ /* var */_sparkMaxCell5: NewBattlefieldSparkMaxCell;

        /* internal */ /* var */_tfLife: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfWorship: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfCanNotWorship: Object /* flash.text.TextField */;

        /* internal */ /* var */_isTweening: Boolean=false;

        /* internal */ /* var */_btnWorship: GButton;

        /* internal */ /* var */_moneyItem: MoneyItem;
    }
